﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using GalaSoft.MvvmLight;
using ZFSDomain.Interface.Base;
using ZFSDomain.Interface.User;
using ZFSDomain.View.User;
using ZFSDomain.ViewModel.User;

namespace ZFSDomain.ViewDialog
{

    /// <summary>
    /// 用户编辑弹窗
    /// </summary>
    public class UserViewDlg : IUserDialog
    {
        /// <summary>
        /// 关联的窗口对象
        /// </summary>
        private UserViewDialog view;
        
        /// <summary>
        /// 关联数据上下文对象
        /// </summary>
        /// <typeparam name="TViewModel"></typeparam>
        /// <param name="viewModel"></param>
        public void BindViewModel<TViewModel>(TViewModel viewModel) where TViewModel : ViewModelBase
        {
            this.GetDialog().DataContext = viewModel;
        }

        /// <summary>
        /// 关闭窗口
        /// </summary>
        public void Close()
        {
            this.GetDialog().Close();
        }

        /// <summary>
        /// 弹出窗口
        /// </summary>
        public bool? ShowDialog()
        {
            var dialog = this.GetDialog();
            dialog.ShowDialog();
            return (dialog.DataContext as UserDialogViewModel).Result;
        }

        /// <summary>
        /// 获取窗口实例
        /// </summary>
        /// <returns></returns>
        public UserViewDialog GetDialog()
        {
            if (view == null)
            {
                view = new UserViewDialog();
            }
            return view;
        }
        
    }
}
